import { requestList } from '@/api/index'

export default {
  namespaced: true,
  actions: {
    async getSearchList(context, val = {}) {
      let result = await requestList(val)
      if (result.code === 200) {
        context.commit('GETSEARCHLIST', result.data)
      }
    }
  },
  mutations: {
    GETSEARCHLIST(state, val) {
      state.searchObj = val
    }
  },
  state: {
    searchObj: {}
  },
  // 可以先简化或者处理state仓库中的数据再用
  getters: {
    goodsList(state) {
      // 必须判断，若请求失败将不会有goodsList数据，会报错
      return state.searchObj.goodsList || []
    },
    trademarkList(state) {
      return state.searchObj.trademarkList || []
    },
    attrsList(state) {
      return state.searchObj.attrsList || []
    }
  }
}
